#include "../include/task_queue.h"

int task_queue_init(taskQueue_t *pQueue){
    bzero(pQueue, sizeof(taskQueue_t));
    return 0;
}
int en_queue(taskQueue_t *pQueue, socket_t fd_client){
    node_t *new_node = (node_t *)calloc(1, sizeof(node_t));
    ERROR_CHECK(new_node, NULL, "calloc when create new node");
    new_node->fd_client = fd_client;
    if (pQueue->pRear == NULL) {
        pQueue->pFront = new_node;
    } else {
        pQueue->pRear->pNext = new_node;
    }   
    pQueue->pRear = new_node;
    pQueue->size++;
    return 0;                                                                                  
}

int de_queue(taskQueue_t *pQueue) {
    node_t *pCurr = pQueue->pFront;
    if (pCurr != NULL) {
        pQueue->pFront = pCurr->pNext;
        if (pQueue->pFront == NULL) {
            pQueue->pRear = NULL;
        }
        free(pCurr);
        pQueue->size--;
    }
    return 0;
}
